package com.dreamwhale.machinery.logistics.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dreamwhale.machinery.goods.entity.DriverInfo;
import com.dreamwhale.machinery.logistics.entity.TransportCompanyInfo;
import com.dreamwhale.machinery.logistics.mapper.TransportCompanyInfoMapper;
import com.dreamwhale.machinery.logistics.service.TransportCompanyInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 物流信息 服务实现类
 * </p>
 *
 * @author Author
 * @since 2020-05-28
 */
@Service
public class TransportCompanyInfoServiceImpl extends ServiceImpl<TransportCompanyInfoMapper, TransportCompanyInfo> implements TransportCompanyInfoService {

    @Resource
    private TransportCompanyInfoMapper transportCompanyInfoMapper;

    @Override
    public int insertTransportCompanyInfos(TransportCompanyInfo transportCompanyInfo) {
        transportCompanyInfo.setCreateTime(LocalDateTime.now());
        return transportCompanyInfoMapper.insert(transportCompanyInfo);
    }

    @Override
    public List<TransportCompanyInfo> selectTransportCompanyInfoMap(Integer userId) {
        QueryWrapper<TransportCompanyInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId).eq("del_flag", 2);
        return transportCompanyInfoMapper.selectList(queryWrapper);
    }

    @Override
    public List<TransportCompanyInfo> selectTransportCompanyInfos(Integer infoid) {
        QueryWrapper<TransportCompanyInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("del_flag", 2).eq("id", infoid);
        return transportCompanyInfoMapper.selectList(queryWrapper);
    }

    @Override
    public TransportCompanyInfo selectTransportCompanyInfoByTypeId(Integer infoId) {
        return transportCompanyInfoMapper.selectTransportCompanyInfoByTypeId(infoId);
    }

    @Override
    public List<TransportCompanyInfo> selectTransportCompanyInfoHome(String title, Integer brandId, String province, String city, Integer type,
                                                                     Integer types, Integer carTypeId) {
        QueryWrapper<TransportCompanyInfo> queryWrapper = new QueryWrapper<>();
        if (type != null) {
            queryWrapper.orderByDesc("count_number");
        }
        if (types != null) {
            queryWrapper.orderByDesc("create_time");
        }
        if (brandId != null) {
            queryWrapper.eq("brand_id", brandId);
        }
        if (province != null && province != "") {
            queryWrapper.eq("province", province);
        }
        if (city != null && city != "") {
            queryWrapper.eq("city", city);
        }

        if (title != null) {
            queryWrapper.like("title", title);
        }
        if (carTypeId != null) {
            queryWrapper.like("car_type_id", carTypeId);
        }

        return transportCompanyInfoMapper.selectList(queryWrapper);
    }
}
